package stream.concurrent;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Zhongzhicong
 * @date 2024/10/25 15:16
 * @version：1.0
 */
public class SynchronizedExample {
    public  void func1() {
//        synchronized (this) {
            for (int i = 0; i < 10; i++) {
                System.out.print(i + " 1");
            }
//        }
    }
    public  void func2() {
//        synchronized (this) {
            for (int i = 0; i < 10; i++) {
                System.out.print(i + " 2");
            }
//        }
    }
    public static void main(String[] args) {
        SynchronizedExample e1 = new SynchronizedExample();
        SynchronizedExample e2 = new SynchronizedExample();
        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> e1.func1());
        executorService.execute(() -> e1.func2());
    }
}
